package Servlet;

import DAO.MessageDAO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name= "ChangeServlet",value = "/ChangeServlet")
public class ChangeServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setCharacterEncoding("UTF-8");
        int state= Integer.parseInt(request.getParameter("state"));
        String NowName=request.getParameter("NowName");
        MessageDAO messageDAO=new MessageDAO();
        String str = null;
            if(state==0){
                str="用户"+NowName+"恢复正常！";
            }
            else if(state==1){
                str="用户"+NowName+"已被封号！";
            }
            else if(state==2){
                str="用户"+NowName+"已被禁言！";
            }
        if(messageDAO.ChangeServlet(NowName, state)){
            response.getWriter().print(str);
        }
        else {
            response.getWriter().print("操作失败！");
        }
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }
}

